home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 4.4 KB | 127 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UKeySelectionBehavior.cp
- // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UKEYSELECTIONBEHAVIOR__
- #include "UKeySelectionBehavior.h"
- #endif
-
- // MacApp
-
- #ifndef __UEVENT__
- #include "UEvent.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- // Toolbox
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
-
- //========================================================================================
- // CLASS TKeySelectionBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TKeySelectionBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TKeySelectionBehavior::TKeySelectionBehavior() :
- fLastKeyUpTime(0)
- {
- // A note on LMGetKeyThresh: the key repeat rate typically ranges
- // from 12 ticks (short) to 40 ticks (long). However, if key repeat
- // is turned off, LMGetKeyThresh returns SHRT_MAX. To prevent an
- // fTimeOutInterval that high, we bound it at 255 ticks (about 4 seconds).
- fTimeOutInterval = Min(::LMGetKeyThresh(),255);
- } // TKeySelectionBehavior::TKeySelectionBehavior
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TKeySelectionBehavior::~TKeySelectionBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior::IKeySelectionBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TKeySelectionBehavior::IKeySelectionBehavior(IDType itsIdentifier)
- {
- this->IBehavior(itsIdentifier);
- } // TKeySelectionBehavior::IKeySelectionBehavior
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior::DoKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MARes
-
- void TKeySelectionBehavior::DoKeyEvent(TToolboxEvent* event)
- {
- if (event->IsOptionKeyPressed() || event->IsControlKeyPressed() || event->fText < chSpace)
- Inherited::DoKeyEvent(event);
- else
- {
- if (event->fEventRecord.when - fLastKeyUpTime >= fTimeOutInterval)
- fKeySequence.Empty();
- fKeySequence += event->fText;
- this->DoKeySelection(fKeySequence);
- fLastKeyUpTime = event->fEventRecord.when;
- }
- } // TKeySelectionBehavior::DoKeyEvent
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior::DoKeySelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MARes
-
- void TKeySelectionBehavior::DoKeySelection(const CStr255& keySequence)
- {
- if (fOwner)
- fOwner->DoKeySelection(keySequence);
- } // TKeySelectionBehavior::DoKeySelection
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior::DoKeyUp:
- //----------------------------------------------------------------------------------------
- #pragma segment MARes
-
- void TKeySelectionBehavior::DoKeyUp(TToolboxEvent* event)
- {
- if (event->IsOptionKeyPressed() || event->IsControlKeyPressed() || event->fText < chSpace)
- Inherited::DoKeyUp(event);
- else
- fLastKeyUpTime = event->fEventRecord.when;
- } // TKeySelectionBehavior::DoKeyUp
-
- //----------------------------------------------------------------------------------------
- // TKeySelectionBehavior::SetTimeOutInterval:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TKeySelectionBehavior::SetTimeOutInterval(long timeOutInterval)
- {
- fTimeOutInterval = timeOutInterval;
- } // TKeySelectionBehavior::SetTimeOutInterval
-
- //----------------------------------------------------------------------------------------
- // End of UKeySelectionBehavior.cp
-
- #pragma segment Inline
-